<template>
  <div class="about">
    <h3>来自主应用的数据</h3>
    <div class="msg-box">
      <el-input placeholder="请输入内容" v-model="fromData" readonly>
        <template slot="prepend">来自主应用：</template>
      </el-input>
      <el-input placeholder="请输入内容" v-model="select" class="input-with-select" readonly>
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="子应用一(home)" value="/layout/app3/home"></el-option>
          <el-option label="子应用二(home)" value="/home"></el-option>
          <el-option label="子应用三(iframe)" value="/layout/iframe"></el-option>
        </el-select>
        <el-button slot="append" @click="btn">跳转</el-button>
      </el-input>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      select: ""
    };
  },
  computed: {
    ...mapState(["fromData"])
  },
  methods: {
    btn() {
      console.log(this.select);
      if (this.select.startsWith("/layout")) {
        if (window.__POWERED_BY_QIANKUN__) {
          this.routerGo(this.select);
        } else {
          this.$message({
            showClose: true,
            message: "当前不是微前端应用",
            type: "warning"
          });
        }
      } else {
        this.$router.push({ path: this.select });
      }
    }
  }
};
</script>

<style scoped>
.about {
  text-align: center;
  line-height: 100px;
}
.msg-box {
  width: 40%;
  margin: 0 auto;
}
.about /deep/ .el-select .el-input {
  width: 150px;
}
.about /deep/ .input-with-select .el-input-group__prepend {
  background-color: #fff;
}
</style>